package milu;

import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import javax.servlet.*;
import javax.servlet.http.*;

import milu.models.*;
import milu.*;

public class AuthFilter implements Filter {
  
    private FilterConfig filterConfig;
    private static final Logger log = Logger.getLogger(AuthFilter.class.getName());  

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

        LOG.info("setting session for user");
        HttpSession session = ((HttpServletRequest) request).getSession(true);
        MyUser myUser = MyUser.getCurrentUser(session);
        request.setAttribute("myUser", myUser);

        filterChain.doFilter(request, response);
    }

    public FilterConfig getFilterConfig() {
        return filterConfig;
    }

    public void init(FilterConfig filterConfig) {
        this.filterConfig = filterConfig;
    }
  
    public void destroy() {
    }
  
}
